<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/jquery.js"></script>
<body>
  <form th:action="@{/search}" method="post">
    图书名称：<input type="text" name="name" th:value="${name}">
    图书类别：<input type="text" name="category" th:value="${category}">
    图书作者：<input type="text" name="author" th:value="${author}">
    <input type="submit" value="提交">
    <a th:href="@{/goAdd}">添加新书</a>
    <table border="1">
      <tr>
        <td>选择</td>
        <td>编号</td>
        <td>书名</td>
        <td>价格</td>
        <td>类型</td>
        <td>库存</td>
        <td>图片</td>
        <td>说明</td>
        <td>作者</td>
        <td>已售</td>
        <td>操作</td>
      </tr>
      <tr th:each="book:${books.list}">
        <td><input type="checkbox" class="ids" th:value="${book.id}" ></td>
        <td th:text="${book.id}"></td>
        <td th:text="${book.name}"></td>
        <td th:text="${book.price}"></td>
        <td th:text="${book.category}"></td>
        <td th:text="${book.pnum}"></td>
        <td th:text="${book.imgurl}"></td>
        <td th:text="${book.description}"></td>
        <td th:text="${book.author}"></td>
        <td th:text="${book.sales}"></td>
        <td><a th:href="@{/goUpdate(id=${book.id})}">修改</a></td>
      </tr>
    </table>
    <br/>
    总页数：<span th:text="${books.pages}"></span>
    总记录数：<span th:text="${books.total}"></span>
    每页条数：<span th:text="${books.pageSize}"></span>
    当前页码：<span th:text="${books.pageNum}"></span>
    <span th:if="${books.pageNum>1}">
      <a th:href="@{/pageList(pageNum = ${books.pageNum - 1})}">上一页</a>
    </span>
    &nbsp;
    <span th:each="p:${#numbers.sequence(1,books.pages)}">
      <a th:href="@{/pageList(pageNum = ${p})}" th:text="${p}"></a>
    </span>
    &nbsp;
    <span th:if="${books.pageNum<books.pages}">
      <a th:href="@{/pageList(pageNum = ${books.pageNum+1})}">下一页</a>
    </span>
    <br/>
    <input type="button" value="删除所选" onclick="delBook()">
  </form>
</body>

<script>
  function delBook(){
    if(confirm("你确定要删除吗？")){
      var ids="";
      $(".ids").each(function (i,e){
        if($(e).is(":checked")){
          var id=$(e).val();
          ids+=id+",";
        }
      });
      if(ids.length==0){
        alert("请选择删除项");
      }else {
        ids=ids.substr(0,ids.length-1);
        location.href="delBook?id="+ids;
      }
    }
  }
</script>
</html>